/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.topcased.SimplePDL.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.topcased.SimplePDL.Resource;
import org.topcased.SimplePDL.ResourceType;
import org.topcased.SimplePDL.SimplePDLPackage;
import org.topcased.SimplePDL.WorkDefinition;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Resource</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.topcased.SimplePDL.impl.ResourceImpl#getWorkDefinition <em>Work Definition</em>}</li>
 *   <li>{@link org.topcased.SimplePDL.impl.ResourceImpl#getOccurrences <em>Occurrences</em>}</li>
 *   <li>{@link org.topcased.SimplePDL.impl.ResourceImpl#getType <em>Type</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ResourceImpl extends EObjectImpl implements Resource {
	/**
	 * The cached value of the '{@link #getWorkDefinition() <em>Work Definition</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getWorkDefinition()
	 * @generated
	 * @ordered
	 */
	protected WorkDefinition workDefinition;

	/**
	 * The default value of the '{@link #getOccurrences() <em>Occurrences</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOccurrences()
	 * @generated
	 * @ordered
	 */
	protected static final int OCCURRENCES_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getOccurrences() <em>Occurrences</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOccurrences()
	 * @generated
	 * @ordered
	 */
	protected int occurrences = OCCURRENCES_EDEFAULT;

	/**
	 * The cached value of the '{@link #getType() <em>Type</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected ResourceType type;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ResourceImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SimplePDLPackage.Literals.RESOURCE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public WorkDefinition getWorkDefinition() {
		if (workDefinition != null && workDefinition.eIsProxy()) {
			InternalEObject oldWorkDefinition = (InternalEObject)workDefinition;
			workDefinition = (WorkDefinition)eResolveProxy(oldWorkDefinition);
			if (workDefinition != oldWorkDefinition) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, SimplePDLPackage.RESOURCE__WORK_DEFINITION, oldWorkDefinition, workDefinition));
			}
		}
		return workDefinition;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public WorkDefinition basicGetWorkDefinition() {
		return workDefinition;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetWorkDefinition(WorkDefinition newWorkDefinition, NotificationChain msgs) {
		WorkDefinition oldWorkDefinition = workDefinition;
		workDefinition = newWorkDefinition;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SimplePDLPackage.RESOURCE__WORK_DEFINITION, oldWorkDefinition, newWorkDefinition);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setWorkDefinition(WorkDefinition newWorkDefinition) {
		if (newWorkDefinition != workDefinition) {
			NotificationChain msgs = null;
			if (workDefinition != null)
				msgs = ((InternalEObject)workDefinition).eInverseRemove(this, SimplePDLPackage.WORK_DEFINITION__NEEDED_RESOURCES, WorkDefinition.class, msgs);
			if (newWorkDefinition != null)
				msgs = ((InternalEObject)newWorkDefinition).eInverseAdd(this, SimplePDLPackage.WORK_DEFINITION__NEEDED_RESOURCES, WorkDefinition.class, msgs);
			msgs = basicSetWorkDefinition(newWorkDefinition, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SimplePDLPackage.RESOURCE__WORK_DEFINITION, newWorkDefinition, newWorkDefinition));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getOccurrences() {
		return occurrences;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setOccurrences(int newOccurrences) {
		int oldOccurrences = occurrences;
		occurrences = newOccurrences;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SimplePDLPackage.RESOURCE__OCCURRENCES, oldOccurrences, occurrences));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ResourceType getType() {
		if (type != null && type.eIsProxy()) {
			InternalEObject oldType = (InternalEObject)type;
			type = (ResourceType)eResolveProxy(oldType);
			if (type != oldType) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, SimplePDLPackage.RESOURCE__TYPE, oldType, type));
			}
		}
		return type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ResourceType basicGetType() {
		return type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setType(ResourceType newType) {
		ResourceType oldType = type;
		type = newType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SimplePDLPackage.RESOURCE__TYPE, oldType, type));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SimplePDLPackage.RESOURCE__WORK_DEFINITION:
				if (workDefinition != null)
					msgs = ((InternalEObject)workDefinition).eInverseRemove(this, SimplePDLPackage.WORK_DEFINITION__NEEDED_RESOURCES, WorkDefinition.class, msgs);
				return basicSetWorkDefinition((WorkDefinition)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SimplePDLPackage.RESOURCE__WORK_DEFINITION:
				return basicSetWorkDefinition(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SimplePDLPackage.RESOURCE__WORK_DEFINITION:
				if (resolve) return getWorkDefinition();
				return basicGetWorkDefinition();
			case SimplePDLPackage.RESOURCE__OCCURRENCES:
				return new Integer(getOccurrences());
			case SimplePDLPackage.RESOURCE__TYPE:
				if (resolve) return getType();
				return basicGetType();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SimplePDLPackage.RESOURCE__WORK_DEFINITION:
				setWorkDefinition((WorkDefinition)newValue);
				return;
			case SimplePDLPackage.RESOURCE__OCCURRENCES:
				setOccurrences(((Integer)newValue).intValue());
				return;
			case SimplePDLPackage.RESOURCE__TYPE:
				setType((ResourceType)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SimplePDLPackage.RESOURCE__WORK_DEFINITION:
				setWorkDefinition((WorkDefinition)null);
				return;
			case SimplePDLPackage.RESOURCE__OCCURRENCES:
				setOccurrences(OCCURRENCES_EDEFAULT);
				return;
			case SimplePDLPackage.RESOURCE__TYPE:
				setType((ResourceType)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SimplePDLPackage.RESOURCE__WORK_DEFINITION:
				return workDefinition != null;
			case SimplePDLPackage.RESOURCE__OCCURRENCES:
				return occurrences != OCCURRENCES_EDEFAULT;
			case SimplePDLPackage.RESOURCE__TYPE:
				return type != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (occurrences: ");
		result.append(occurrences);
		result.append(')');
		return result.toString();
	}

} //ResourceImpl
